import { getServerConfig,getFileVersion } from '../libs/utils'

const { client: clientConfig } = getServerConfig()

import { GlobVar } from '../global'

const renderLogin = async (ctx:any) => {
    ctx.cookies.set('referer', ctx.query.referer)
    
    // 判断一下登录是否失效
    const token = ctx.cookies.get('token') || ''
    if(token){
        ctx.redirect('/')
    }else{
        await renderIndex(ctx, {
        })
    }
    
  }

  const renderIndex = async (ctx:any, params:any) => {
    await ctx.render('index', {
      t: ctx.t.bind(ctx),
      isDev: GlobVar.MODE_DEV,
      version: getFileVersion,
      title: clientConfig.title,
      config: JSON.stringify(clientConfig),
    })
  }

  export { renderLogin }

